###### This file produce Figures 5 & 6 from the Text Analysis Output. #######

library(ggplot2)
library(extrafont)

counts <- read.csv("Figure_5_6.csv")


########### Figure 5: Newspaper Article Count #########

paperNo <- data.frame(
  year = c(1979,1980,1981,1982,1983,1984,1985,1986,1987,1989,1990,1991,1992,1993,1994,1995,1996,1997,1998,1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012,2013),
  counts = c(1,1,3,2,3,2,1,2,1,3,8,1,6,14,8,11,13,13,15,22,110,137,92,126,285,570,853,834,855,1027,1406,1424,1837,3077)
)


p <- ggplot(data=paperNo, aes(x=year, y=counts)) 
p + geom_line() + geom_point(size=3)+
  theme_bw()+ 
  geom_vline(xintercept = 2000, linetype='dashed', color='Grey60')+
  #geom_text("TVPA", aes(x=2001, y=2000, label="TVPA"), size=3, parse=T)+
  geom_vline(xintercept = 2003, linetype='dashed', color='Grey60')+
  geom_vline(xintercept = 2005, linetype='dashed', color='Grey60')+
  geom_vline(xintercept = 2008, linetype='dashed', color='Grey60')+
  geom_vline(xintercept = 2013, linetype='dashed', color='Grey60')+
  scale_y_continuous(name="Number of Articles\n")+
  scale_x_continuous(name="\nYear")  + theme(text=element_text(family="Garamond"))

ggsave(file="BonillaMo_Figure5.jpg", width=8, height=5, units="in", dpi=600)


###### Producing Figure 6 #######

graph <- data.frame(
  year = counts$year,
  hr = c(counts$HR * counts$count),
  foreign = c(counts$Foreign * counts$count),
  imm = c(counts$Immigration * counts$count),
  sex = c(counts$Sex  * counts$count),
  labor = c(counts$Labor * counts$count),
  security = c(counts$Security  * counts$count)
)

graph2 <- data.frame(
  topic = as.factor(c(rep(1,14), rep(2,14),rep(3,14),rep(4,14),rep(5,14))),
  year = c(rep(counts$year, 5)),           
  counts = c((counts$Foreign * counts$count),(counts$Immigration * counts$count),
             (counts$Sex  * counts$count),(counts$Labor * counts$count),(counts$Security  * counts$count))
)


p <- ggplot(data=graph2, aes(x=year, y=counts, group=topic, colour=topic)) 
p + geom_line() + geom_point(aes(shape=topic),size=3)+
  theme_bw()+ 
  scale_y_continuous(name="Number of Articles\n")+
  scale_x_continuous(name="\nYear")+
  scale_colour_manual(name="Topic", values=c("Black","Grey25", "Grey40","Grey50","Grey65","Grey75"), 
                      breaks=c(1,2,3,4,5),
                      labels=c("Foreign","Immigration","Sex Trafficking", 
                               "Labor Trafficking","Security"))+
  scale_shape_manual(name="Topic", values=c(15,16,17,21,22,23), breaks=c(1,2,3,4,5),
                     labels=c("Foreign","Immigration","Sex Trafficking", 
                              "Labor Trafficking","Security"))  + 
  theme(text=element_text(family="Garamond"))

ggsave(file="BonillaMo_Figure6.jpg", width=11, height=6, units="in", dpi=600)

